/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projectshanghai;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;

/**
 *
 * @author Eric-Standard
 */
public class KeyMonitor implements KeyListener {

    private ArrayList<Integer> keys;

    public KeyMonitor() {
        keys = new ArrayList<Integer>();
    }

    public boolean isKeyPressed(int i) {
        return keys.indexOf(i) != -1;
    }

    public ArrayList<Integer> getPressedKeys() {
        return keys;
    }

    public void clearKeys() {
        keys.clear();
    }

    @Override
    public void keyTyped(KeyEvent e) {
    }

    @Override
    public void keyPressed(KeyEvent e) {
        int keyCode = e.getKeyCode();
        if (!isKeyPressed(keyCode)) {
            keys.add(keyCode);
        }
    }

    @Override
    public void keyReleased(KeyEvent e) {
        int keyCode = e.getKeyCode();
        keys.remove(Integer.valueOf(keyCode));
    }
}
